package org.notepad.adapter;

import java.util.ArrayList;

import org.notepad.R;
import org.notepad.bean.TimeRecord;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class TimeTrackerAdapter extends BaseAdapter {
	
	public TimeTrackerAdapter(){
		tr.add(new TimeRecord("2013-1-13","first note"));
		tr.add(new TimeRecord("2013-1-13","second note"));
	}
	
	private ArrayList<TimeRecord> tr = new ArrayList<TimeRecord>();
	@Override
	public int getCount() {
		return tr.size();
	}

	@Override
	public Object getItem(int index) {
		return tr.get(index);
	}

	@Override
	public long getItemId(int index) {
		return index;
	}

	@Override
	public View getView(int index, View view, ViewGroup parent) {
		if(view == null){
			LayoutInflater inflater = LayoutInflater.from(parent.getContext());
			view = inflater.inflate(R.layout.time_list_item,parent,false);
		}
		TimeRecord timeRecord = tr.get(index);
		TextView timeView = (TextView) view.findViewById(R.id.time_view);
		timeView.setText(timeRecord.getTime());
		TextView noteView = (TextView) view.findViewById(R.id.note_view);
		noteView.setText(timeRecord.getNotes());
		return view;
	}
	
	public void addTimeTracker(TimeRecord timeRecord){
		tr.add(timeRecord);
	}
}
